home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / cfb / cfbseg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-15  |  18.5 KB  |  812 lines

  1. /***********************************************************
  2. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  3. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Digital or MIT not be
  12. used in advertising or publicity pertaining to distribution of the
  13. software without specific, written prior permission.  
  14.  
  15. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  18. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21. SOFTWARE.
  22.  
  23. ******************************************************************/
  24. /* $XConsortium: cfbline.c,v 1.12 89/11/19 16:16:05 rws Exp $ */
  25. #include "X.h"
  26.  
  27. #include "gcstruct.h"
  28. #include "windowstr.h"
  29. #include "pixmapstr.h"
  30. #include "regionstr.h"
  31. #include "scrnintstr.h"
  32. #include "mistruct.h"
  33.  
  34. #include "cfb.h"
  35. #include "cfbmskbits.h"
  36.  
  37. /* single-pixel lines on a color frame buffer
  38.  
  39.    NON-SLOPED LINES
  40.    horizontal lines are always drawn left to right; we have to
  41. move the endpoints right by one after they're swapped.
  42.    horizontal lines will be confined to a single band of a
  43. region.  the code finds that band (giving up if the lower
  44. bound of the band is above the line we're drawing); then it
  45. finds the first box in that band that contains part of the
  46. line.  we clip the line to subsequent boxes in that band.
  47.    vertical lines are always drawn top to bottom (y-increasing.)
  48. this requires adding one to the y-coordinate of each endpoint
  49. after swapping.
  50.  
  51.    SLOPED LINES
  52.    when clipping a sloped line, we bring the second point inside
  53. the clipping box, rather than one beyond it, and then add 1 to
  54. the length of the line before drawing it.  this lets us use
  55. the same box for finding the outcodes for both endpoints.  since
  56. the equation for clipping the second endpoint to an edge gives us
  57. 1 beyond the edge, we then have to move the point towards the
  58. first point by one step on the major axis.
  59.    eventually, there will be a diagram here to explain what's going
  60. on.  the method uses Cohen-Sutherland outcodes to determine
  61. outsideness, and a method similar to Pike's layers for doing the
  62. actual clipping.
  63.  
  64. */
  65.  
  66. #define OUTCODES(result, x, y, pbox) \
  67.     if (x < pbox->x1) \
  68.     result |= OUT_LEFT; \
  69.     else if (x >= pbox->x2) \
  70.     result |= OUT_RIGHT; \
  71.     if (y < pbox->y1) \
  72.     result |= OUT_ABOVE; \
  73.     else if (y >= pbox->y2) \
  74.     result |= OUT_BELOW;
  75.  
  76. /*
  77. #define SignTimes(sign, n) ((sign) * ((int)(n)))
  78. */
  79.  
  80. #define SignTimes(sign, n) \
  81.     ( ((sign)<0) ? -(n) : (n) )
  82.  
  83. #define SWAPINT(i, j) \
  84. {  register int _t = i; \
  85.    i = j; \
  86.    j = _t; \
  87. }
  88.  
  89. #define SWAPPT(i, j) \
  90. {  register DDXPointRec _t; \
  91.    _t = i; \
  92.    i = j; \
  93.    j = _t; \
  94. }
  95.  
  96. void
  97. #ifdef POLYSEGMENT
  98. cfbSegmentSS (pDrawable, pGC, nseg, pSeg)
  99.     DrawablePtr    pDrawable;
  100.     GCPtr    pGC;
  101.     int        nseg;
  102.     register xSegment    *pSeg;
  103. #else
  104. cfbLineSS (pDrawable, pGC, mode, npt, pptInit)
  105.     DrawablePtr pDrawable;
  106.     GCPtr    pGC;
  107.     int        mode;        /* Origin or Previous */
  108.     int        npt;        /* number of points */
  109.     DDXPointPtr pptInit;
  110. #endif
  111. {
  112.     int nboxInit;
  113.     register int nbox;
  114.     BoxPtr pboxInit;
  115.     register BoxPtr pbox;
  116. #ifndef POLYSEGMENT
  117.     register DDXPointPtr ppt;    /* pointer to list of translated points */
  118. #endif
  119.  
  120.     unsigned int oc1;        /* outcode of point 1 */
  121.     unsigned int oc2;        /* outcode of point 2 */
  122.  
  123.     int *addrl;        /* address of destination pixmap */
  124.     int nlwidth;        /* width in longwords of destination pixmap */
  125.     int xorg, yorg;        /* origin of window */
  126.  
  127.     int adx;        /* abs values of dx and dy */
  128.     int ady;
  129.     int signdx;        /* sign of dx and dy */
  130.     int signdy;
  131.     int e, e1, e2;        /* bresenham error and increments */
  132.     int len;            /* length of segment */
  133.     int axis;            /* major axis */
  134.  
  135.                 /* a bunch of temporaries */
  136.     int tmp;
  137.     register int y1, y2;
  138.     register int x1, x2;
  139.     RegionPtr cclip;
  140.     unsigned long   pixel;
  141.     int            alu;
  142.     unsigned long   planemask;
  143.  
  144.     cclip = ((cfbPrivGC *)(pGC->devPrivates[cfbGCPrivateIndex].ptr))->pCompositeClip;
  145.     pboxInit = REGION_RECTS(cclip);
  146.     nboxInit = REGION_NUM_RECTS(cclip);
  147.  
  148.     if (pDrawable->type == DRAWABLE_WINDOW)
  149.     {
  150.     addrl = (int *)
  151.         (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devPrivate.ptr);
  152.     nlwidth = (int)
  153.         (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devKind) >> 2;
  154.     }
  155.     else
  156.     {
  157.     addrl = (int *)(((PixmapPtr)pDrawable)->devPrivate.ptr);
  158.     nlwidth = (int)(((PixmapPtr)pDrawable)->devKind) >> 2;
  159.     }
  160.  
  161.     alu = pGC->alu;
  162.     pixel = pGC->fgPixel;
  163.     planemask = pGC->planemask;
  164.     if (alu == GXinvert)
  165.     {
  166.     pixel = pGC->planemask;
  167.     alu = GXxor;
  168.     planemask = PMSK;
  169.     }
  170.     xorg = pDrawable->x;
  171.     yorg = pDrawable->y;
  172. #ifdef POLYSEGMENT
  173.     while (nseg--)
  174. #else
  175.     ppt = pptInit;
  176.     x2 = ppt->x + xorg;
  177.     y2 = ppt->y + yorg;
  178.     while(--npt)
  179. #endif
  180.     {
  181.     nbox = nboxInit;
  182.     pbox = pboxInit;
  183.  
  184. #ifdef POLYSEGMENT
  185.     x1 = pSeg->x1 + xorg;
  186.     y1 = pSeg->y1 + yorg;
  187.     x2 = pSeg->x2 + xorg;
  188.     y2 = pSeg->y2 + yorg;
  189.     pSeg++;
  190. #else
  191.     x1 = x2;
  192.     y1 = y2;
  193.     ++ppt;
  194.     if (mode == CoordModePrevious)
  195.     {
  196.         xorg = x1;
  197.         yorg = y1;
  198.     }
  199.     x2 = ppt->x + xorg;
  200.     y2 = ppt->y + yorg;
  201. #endif
  202.  
  203.     if (x1 == x2)
  204.     {
  205.         /* make the line go top to bottom of screen, keeping
  206.            endpoint semantics
  207.         */
  208.         if (y1 > y2)
  209.         {
  210.         register int tmp;
  211.  
  212.         tmp = y2;
  213.         y2 = y1 + 1;
  214.         y1 = tmp + 1;
  215.         }
  216. #ifdef POLYSEGMENT
  217.         if (pGC->capStyle != CapNotLast)
  218.         y2++;
  219. #endif
  220.         /* get to first band that might contain part of line */
  221.         while ((nbox) && (pbox->y2 <= y1))
  222.         {
  223.         pbox++;
  224.         nbox--;
  225.         }
  226.  
  227.         if (nbox)
  228.         {
  229.         /* stop when lower edge of box is beyond end of line */
  230.         while((nbox) && (y2 >= pbox->y1))
  231.         {
  232.             if ((x1 >= pbox->x1) && (x1 < pbox->x2))
  233.             {
  234.             int y1t, y2t;
  235.             /* this box has part of the line in it */
  236.             y1t = max(y1, pbox->y1);
  237.             y2t = min(y2, pbox->y2);
  238.             if (y1t != y2t)
  239.             {
  240.                 cfbVertS (alu, pixel, planemask,
  241.                       addrl, nlwidth, 
  242.                       x1, y1t, y2t-y1t);
  243.             }
  244.             }
  245.             nbox--;
  246.             pbox++;
  247.         }
  248.         }
  249. #ifndef POLYSEGMENT
  250.         y2 = ppt->y + yorg;
  251. #endif
  252.     }
  253.     else if (y1 == y2)
  254.     {
  255.         /* force line from left to right, keeping
  256.            endpoint semantics
  257.         */
  258.         if (x1 > x2)
  259.         {
  260.         register int tmp;
  261.  
  262.         tmp = x2;
  263.         x2 = x1 + 1;
  264.         x1 = tmp + 1;
  265.         }
  266. #ifdef POLYSEGMENT
  267.         if (pGC->capStyle != CapNotLast)
  268.         x2++;
  269. #endif
  270.  
  271.         /* find the correct band */
  272.         while( (nbox) && (pbox->y2 <= y1))
  273.         {
  274.         pbox++;
  275.         nbox--;
  276.         }
  277.  
  278.         /* try to draw the line, if we haven't gone beyond it */
  279.         if ((nbox) && (pbox->y1 <= y1))
  280.         {
  281.         /* when we leave this band, we're done */
  282.         tmp = pbox->y1;
  283.         while((nbox) && (pbox->y1 == tmp))
  284.         {
  285.             int    x1t, x2t;
  286.  
  287.             if (pbox->x2 <= x1)
  288.             {
  289.             /* skip boxes until one might contain start point */
  290.             nbox--;
  291.             pbox++;
  292.             continue;
  293.             }
  294.  
  295.             /* stop if left of box is beyond right of line */
  296.             if (pbox->x1 >= x2)
  297.             {
  298.             nbox = 0;
  299.             break;
  300.             }
  301.  
  302.             x1t = max(x1, pbox->x1);
  303.             x2t = min(x2, pbox->x2);
  304.             if (x1t != x2t)
  305.             {
  306.             cfbHorzS (alu, pixel, planemask,
  307.                   addrl, nlwidth, 
  308.                   x1t, y1, x2t-x1t);
  309.             }
  310.             nbox--;
  311.             pbox++;
  312.         }
  313.         }
  314. #ifndef POLYSEGMENT
  315.         x2 = ppt->x + xorg;
  316. #endif
  317.     }
  318.     else    /* sloped line */
  319.     {
  320.         signdx = 1;
  321.         if ((adx = x2 - x1) < 0)
  322.         {
  323.         adx = -adx;
  324.         signdx = -1;
  325.         }
  326.         signdy = 1;
  327.         if ((ady = y2 - y1) < 0)
  328.         {
  329.         ady = -ady;
  330.         signdy = -1;
  331.         }
  332.  
  333.         if (adx > ady)
  334.         {
  335.         axis = X_AXIS;
  336.         e1 = ady << 1;
  337.         e2 = e1 - (adx << 1);
  338.         e = e1 - adx;
  339.  
  340.         }
  341.         else
  342.         {
  343.         axis = Y_AXIS;
  344.         e1 = adx << 1;
  345.         e2 = e1 - (ady << 1);
  346.         e = e1 - ady;
  347.         }
  348.  
  349.         /* we have bresenham parameters and two points.
  350.            all we have to do now is clip and draw.
  351.         */
  352.  
  353.         while(nbox--)
  354.         {
  355.         oc1 = 0;
  356.         oc2 = 0;
  357.         OUTCODES(oc1, x1, y1, pbox);
  358.         OUTCODES(oc2, x2, y2, pbox);
  359.         if ((oc1 | oc2) == 0)
  360.         {
  361.             if (axis == X_AXIS)
  362.             len = adx;
  363.             else
  364.             len = ady;
  365. #ifdef POLYSEGMENT
  366.             if (pGC->capStyle != CapNotLast)
  367.             len++;
  368. #endif
  369.             cfbBresS (alu, pixel, planemask,
  370.               addrl, nlwidth,
  371.               signdx, signdy, axis, x1, y1,
  372.               e, e1, e2, len);
  373.             break;
  374.         }
  375.         else if (oc1 & oc2)
  376.         {
  377.             pbox++;
  378.         }
  379.         else
  380.         {
  381.                 /*
  382.                   * let the mfb helper routine do our work;
  383.                   * better than duplicating code...
  384.                   */
  385.                 BoxRec box;
  386.                     DDXPointRec pt1Copy;    /* clipped start point */
  387.                     DDXPointRec pt2Copy;    /* clipped end point */
  388.                     int err;            /* modified bresenham error term */
  389.                     int clip1, clip2;        /* clippedness of the endpoints */
  390.                 
  391.                     int clipdx, clipdy;        /* difference between clipped and
  392.                                          unclipped start point */
  393.             DDXPointRec    pt1;
  394.                 
  395.         
  396.                 pt1.x = pt1Copy.x = x1;
  397.             pt1.y = pt1Copy.y = y1;
  398.                 pt2Copy.x = x2;
  399.             pt2Copy.y = y2;
  400.                 box.x1 = pbox->x1;
  401.                 box.y1 = pbox->y1;
  402.                 box.x2 = pbox->x2-1;
  403.                 box.y2 = pbox->y2-1;
  404.                 clip1 = 0;
  405.                 clip2 = 0;
  406.         
  407.             if (mfbClipLine (pbox, box,
  408.                      &pt1, &pt1Copy, &pt2Copy, 
  409.                      adx, ady, signdx, signdy, axis,
  410.                      &clip1, &clip2) == 1)
  411.             {
  412.                 if (axis == X_AXIS)
  413.                 len = abs(pt2Copy.x - pt1Copy.x);
  414.                 else
  415.                 len = abs(pt2Copy.y - pt1Copy.y);
  416.     
  417. #ifdef POLYSEGMENT
  418.                 if (clip2 != 0 || pGC->capStyle != CapNotLast)
  419.                 len++;
  420. #else
  421.                 len += (clip2 != 0);
  422. #endif
  423.                 if (len)
  424.                 {
  425.                 /* unwind bresenham error term to first point */
  426.                 if (clip1)
  427.                 {
  428.                     clipdx = abs(pt1Copy.x - x1);
  429.                     clipdy = abs(pt1Copy.y - y1);
  430.                     if (axis == X_AXIS)
  431.                     err = e+((clipdy*e2) + ((clipdx-clipdy)*e1));
  432.                     else
  433.                     err = e+((clipdx*e2) + ((clipdy-clipdx)*e1));
  434.                 }
  435.                 else
  436.                     err = e;
  437.                 cfbBresS   
  438.                      (alu, pixel, planemask,
  439.                       addrl, nlwidth,
  440.                       signdx, signdy, axis, pt1Copy.x, pt1Copy.y,
  441.                       err, e1, e2, len);
  442.                 }
  443.             }
  444.             pbox++;
  445.         }
  446.         } /* while (nbox--) */
  447.     } /* sloped line */
  448.     } /* while (nline--) */
  449.  
  450. #ifndef POLYSEGMENT
  451.     /* paint the last point if the end style isn't CapNotLast.
  452.        (Assume that a projecting, butt, or round cap that is one
  453.         pixel wide is the same as the single pixel of the endpoint.)
  454.     */
  455.  
  456.     if ((pGC->capStyle != CapNotLast) &&
  457.     ((ppt->x != pptInit->x) ||
  458.      (ppt->y != pptInit->y) ||
  459.      (ppt == pptInit + 1)))
  460.     {
  461.     nbox = nboxInit;
  462.     pbox = pboxInit;
  463.     while (nbox--)
  464.     {
  465.         if ((x2 >= pbox->x1) &&
  466.         (y2 >= pbox->y1) &&
  467.         (x2 <  pbox->x2) &&
  468.         (y2 <  pbox->y2))
  469.         {
  470.         unsigned long mask;
  471.         unsigned long scrbits;
  472.         unsigned long pix = PFILL (pixel);
  473.         extern int cfbmask[4];
  474.  
  475.         mask = cfbmask[x2 & PIM];
  476.         addrl += (y2 * nlwidth) + (x2 >> PWSH);
  477.         scrbits = *addrl;
  478.         *addrl = (scrbits & ~mask) |
  479.              (DoRop (alu, pix, scrbits) & mask);
  480.         break;
  481.         }
  482.         else
  483.         pbox++;
  484.     }
  485.     }
  486. #endif
  487. }
  488.  
  489. /*
  490.  * Draw dashed 1-pixel lines.
  491.  */
  492.  
  493. void
  494. #ifdef POLYSEGMENT
  495. cfbSegmentSD (pDrawable, pGC, nseg, pSeg)
  496.     DrawablePtr    pDrawable;
  497.     register GCPtr    pGC;
  498.     int        nseg;
  499.     register xSegment    *pSeg;
  500. #else
  501. cfbLineSD( pDrawable, pGC, mode, npt, pptInit)
  502.     DrawablePtr pDrawable;
  503.     register GCPtr pGC;
  504.     int mode;        /* Origin or Previous */
  505.     int npt;        /* number of points */
  506.     DDXPointPtr pptInit;
  507. #endif
  508. {
  509.     int nboxInit;
  510.     register int nbox;
  511.     BoxPtr pboxInit;
  512.     register BoxPtr pbox;
  513. #ifndef POLYSEGMENT
  514.     register DDXPointPtr ppt;    /* pointer to list of translated points */
  515. #endif
  516.  
  517.     register unsigned int oc1;        /* outcode of point 1 */
  518.     register unsigned int oc2;        /* outcode of point 2 */
  519.  
  520.     int *addrl;        /* address of destination pixmap */
  521.     int nlwidth;        /* width in longwords of destination pixmap */
  522.     int xorg, yorg;        /* origin of window */
  523.  
  524.     int adx;        /* abs values of dx and dy */
  525.     int ady;
  526.     int signdx;        /* sign of dx and dy */
  527.     int signdy;
  528.     int e, e1, e2;        /* bresenham error and increments */
  529.     int len;            /* length of segment */
  530.     int axis;            /* major axis */
  531.     int x1, x2, y1, y2;
  532.     RegionPtr cclip;
  533.     unsigned long   fg, bg;
  534.     int            alu;
  535.     unsigned long   planemask;
  536.     unsigned char   *pDash;
  537.     int            dashOffset;
  538.     int            numInDashList;
  539.     int            dashIndex;
  540.     int            isDoubleDash;
  541.     int            dashIndexTmp, dashOffsetTmp;
  542.     int            unclippedlen;
  543.  
  544.     cclip = ((cfbPrivGC *)(pGC->devPrivates[cfbGCPrivateIndex].ptr))->pCompositeClip;
  545.     pboxInit = REGION_RECTS(cclip);
  546.     nboxInit = REGION_NUM_RECTS(cclip);
  547.  
  548.     if (pDrawable->type == DRAWABLE_WINDOW)
  549.     {
  550.     addrl = (int *)
  551.         (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devPrivate.ptr);
  552.     nlwidth = (int)
  553.         (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devKind) >> 2;
  554.     }
  555.     else
  556.     {
  557.     addrl = (int *)(((PixmapPtr)pDrawable)->devPrivate.ptr);
  558.     nlwidth = (int)(((PixmapPtr)pDrawable)->devKind) >> 2;
  559.     }
  560.  
  561.     /* compute initial dash values */
  562.      
  563.     pDash = (unsigned char *) pGC->dash;
  564.     numInDashList = pGC->numInDashList;
  565.     isDoubleDash = (pGC->lineStyle == LineDoubleDash);
  566.     dashIndex = 0;
  567.     dashOffset = 0;
  568.     miStepDash ((int)pGC->dashOffset, &dashIndex, pDash,
  569.         numInDashList, &dashOffset);
  570.  
  571.     fg = pGC->fgPixel;
  572.     bg = pGC->bgPixel;
  573.     alu = pGC->alu;
  574.     planemask = pGC->planemask;
  575.     if (alu == GXinvert)
  576.     {
  577.     fg = bg = pGC->planemask;
  578.     alu = GXxor;
  579.     planemask = PMSK;
  580.     }
  581.  
  582.     xorg = pDrawable->x;
  583.     yorg = pDrawable->y;
  584. #ifdef POLYSEGMENT
  585.     while (nseg--)
  586. #else
  587.     ppt = pptInit;
  588.     x2 = ppt->x + xorg;
  589.     y2 = ppt->y + yorg;
  590.     while(--npt)
  591. #endif
  592.     {
  593.     nbox = nboxInit;
  594.     pbox = pboxInit;
  595.  
  596. #ifdef POLYSEGMENT
  597.     x1 = pSeg->x1 + xorg;
  598.     y1 = pSeg->y1 + yorg;
  599.     x2 = pSeg->x2 + xorg;
  600.     y2 = pSeg->y2 + yorg;
  601.     pSeg++;
  602. #else
  603.     x1 = x2;
  604.     y1 = y2;
  605.     ++ppt;
  606.     if (mode == CoordModePrevious)
  607.     {
  608.         xorg = x1;
  609.         yorg = y1;
  610.     }
  611.     x2 = ppt->x + xorg;
  612.     y2 = ppt->y + yorg;
  613. #endif
  614.  
  615.     adx = x2 - x1;
  616.     ady = y2 - y1;
  617.     signdx = sign(adx);
  618.     signdy = sign(ady);
  619.     adx = abs(adx);
  620.     ady = abs(ady);
  621.  
  622.     if (adx > ady)
  623.     {
  624.         axis = X_AXIS;
  625.         e1 = ady << 1;
  626.         e2 = e1 - (adx << 1);
  627.         e = e1 - adx;
  628.         unclippedlen = adx;
  629.     }
  630.     else
  631.     {
  632.         axis = Y_AXIS;
  633.         e1 = adx << 1;
  634.         e2 = e1 - (ady << 1);
  635.         e = e1 - ady;
  636.         unclippedlen = ady;
  637.     }
  638.  
  639.     /* we have bresenham parameters and two points.
  640.        all we have to do now is clip and draw.
  641.     */
  642.  
  643.     while(nbox--)
  644.     {
  645.         oc1 = 0;
  646.         oc2 = 0;
  647.         OUTCODES(oc1, x1, y1, pbox);
  648.         OUTCODES(oc2, x2, y2, pbox);
  649.         if ((oc1 | oc2) == 0)
  650.         {
  651. #ifdef POLYSEGMENT
  652.         if (pGC->capStyle != CapNotLast)
  653.             unclippedlen++;
  654.         dashIndexTmp = dashIndex;
  655.         dashOffsetTmp = dashOffset;
  656.         cfbBresD (alu, fg, bg, planemask,
  657.               &dashIndexTmp, pDash, numInDashList,
  658.               &dashOffsetTmp, isDoubleDash,
  659.               addrl, nlwidth,
  660.               signdx, signdy, axis, x1, y1,
  661.               e, e1, e2, unclippedlen);
  662.         break;
  663. #else
  664.         cfbBresD (alu, fg, bg, planemask,
  665.               &dashIndex, pDash, numInDashList,
  666.               &dashOffset, isDoubleDash,
  667.               addrl, nlwidth,
  668.               signdx, signdy, axis, x1, y1,
  669.               e, e1, e2, unclippedlen);
  670.         goto dontStep;
  671. #endif
  672.         }
  673.         else if (oc1 & oc2)
  674.         {
  675.         pbox++;
  676.         }
  677.         else /* have to clip */
  678.         {
  679.         /*
  680.          * let the mfb helper routine do our work;
  681.          * better than duplicating code...
  682.          */
  683.         BoxRec box;
  684.         DDXPointRec pt1Copy;    /* clipped start point */
  685.         DDXPointRec pt2Copy;    /* clipped end point */
  686.         int err;            /* modified bresenham error term */
  687.         int clip1, clip2;        /* clippedness of the endpoints */
  688.         
  689.         int clipdx, clipdy;        /* difference between clipped and
  690.                            unclipped start point */
  691.         DDXPointRec    pt1;
  692.     
  693.         pt1.x = pt1Copy.x = x1;
  694.         pt1.y = pt1Copy.y = y1;
  695.         pt2Copy.x = x2;
  696.         pt2Copy.y = y2;
  697.         box.x1 = pbox->x1;
  698.         box.y1 = pbox->y1;
  699.         box.x2 = pbox->x2-1;
  700.         box.y2 = pbox->y2-1;
  701.         clip1 = 0;
  702.         clip2 = 0;
  703.     
  704.         if (mfbClipLine (pbox, box,
  705.                        &pt1, &pt1Copy, &pt2Copy, 
  706.                        adx, ady, signdx, signdy, axis,
  707.                        &clip1, &clip2) == 1)
  708.         {
  709.     
  710.             dashIndexTmp = dashIndex;
  711.             dashOffsetTmp = dashOffset;
  712.             if (clip1)
  713.             {
  714.                 int dlen;
  715.     
  716.                 if (axis == X_AXIS)
  717.                 dlen = abs(pt1Copy.x - x1);
  718.                 else
  719.                 dlen = abs(pt1Copy.y - y1);
  720.                 miStepDash (dlen, &dashIndexTmp, pDash,
  721.                     numInDashList, &dashOffsetTmp);
  722.             }
  723.             if (axis == X_AXIS)
  724.                 len = abs(pt2Copy.x - pt1Copy.x);
  725.             else
  726.                 len = abs(pt2Copy.y - pt1Copy.y);
  727.     
  728. #ifdef POLYSEGMENT
  729.             if (clip2 != 0 || pGC->capStyle != CapNotLast)
  730.                 len++;
  731. #else
  732.             len += (clip2 != 0);
  733. #endif
  734.             if (len)
  735.             {
  736.                 /* unwind bresenham error term to first point */
  737.                 if (clip1)
  738.                 {
  739.                 clipdx = abs(pt1Copy.x - x1);
  740.                 clipdy = abs(pt1Copy.y - y1);
  741.                 if (axis == X_AXIS)
  742.                     err = e+((clipdy*e2) + ((clipdx-clipdy)*e1));
  743.                 else
  744.                     err = e+((clipdx*e2) + ((clipdy-clipdx)*e1));
  745.                 }
  746.                 else
  747.                 err = e;
  748.                 cfbBresD (alu, fg, bg, planemask,
  749.                         &dashIndexTmp, pDash, numInDashList,
  750.                         &dashOffsetTmp, isDoubleDash,
  751.                         addrl, nlwidth,
  752.                         signdx, signdy, axis, pt1Copy.x, pt1Copy.y,
  753.                         err, e1, e2, len);
  754.             }
  755.         }
  756.         pbox++;
  757.         }
  758.     } /* while (nbox--) */
  759. #ifndef POLYSEGMENT
  760.     /*
  761.      * walk the dash list around to the next line
  762.      */
  763.     miStepDash (unclippedlen, &dashIndex, pDash,
  764.             numInDashList, &dashOffset);
  765. dontStep:    ;
  766. #endif
  767.     } /* while (nline--) */
  768.  
  769. #ifndef POLYSEGMENT
  770.     /* paint the last point if the end style isn't CapNotLast.
  771.        (Assume that a projecting, butt, or round cap that is one
  772.         pixel wide is the same as the single pixel of the endpoint.)
  773.     */
  774.  
  775.     if ((pGC->capStyle != CapNotLast) &&
  776.         ((dashIndex & 1) == 0 || isDoubleDash) &&
  777.     ((ppt->x != pptInit->x) ||
  778.      (ppt->y != pptInit->y) ||
  779.      (ppt == pptInit + 1)))
  780.     {
  781.     nbox = nboxInit;
  782.     pbox = pboxInit;
  783.     while (nbox--)
  784.     {
  785.         if ((x2 >= pbox->x1) &&
  786.         (y2 >= pbox->y1) &&
  787.         (x2 <  pbox->x2) &&
  788.         (y2 <  pbox->y2))
  789.         {
  790.         unsigned long mask;
  791.         unsigned long scrbits;
  792.         unsigned long pix;
  793.         extern int cfbmask[4];
  794.  
  795.         pix = fg;
  796.         if (dashIndex & 1)
  797.             pix = bg;
  798.         pix = PFILL (pix);
  799.         mask = cfbmask[x2 & PIM];
  800.         addrl += (y2 * nlwidth) + (x2 >> PWSH);
  801.         scrbits = *addrl;
  802.         *addrl = (scrbits & ~mask) |
  803.              (DoRop (alu, pix, scrbits) & mask);
  804.         break;
  805.         }
  806.         else
  807.         pbox++;
  808.     }
  809.     }
  810. #endif
  811. }
  812.